﻿using Blm.Utils.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Ms;
using VisionCloud.Utility;

namespace VisionCloud.Api.Controllers.Inner
{
    [SystemModule("建模任务相关接口")]
    [ApiVersion("1.0")]
    [Route("api/inner/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "建模任务相关接口")]
    public class ModelingTaskController : ApiBaseController
    {
        public ILogger<ModelingTaskController> logger { get; set; }

        public TaskDataUploadService TaskDataUploadService { set; get; }

        /// <summary>
        /// 更新建模任务信息
        /// </summary>
        /// <param name="taskData"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> UploadTaskInfo(ModelingTaskDataDto taskData)
        {
            try
            {
                if (taskData?.TaskDataset?.Tables?.Count > 0 && !string.IsNullOrEmpty(taskData.DeviceNo) && !string.IsNullOrEmpty(taskData.MinioPath))
                {
                    TaskDataUploadService.UploadTableFromDataset(taskData.TaskDataset, taskData.DeviceNo, taskData.ResultDataFilePath);
                    return ApiResult.Success();
                }
                else
                    return ApiResult.Error("参数不可为空");
            }
            catch (Exception ex)
            {
                Logger.Error("api/inner/ModelingTask/UploadTaskInfo has Error: " + ex.Message, ex);
                return ApiResult.Error(ex.Message);
            }
        }
    }
}